import { defineStore } from 'pinia'
import {ref} from 'vue'
import Logo from '@/assets/logo.png'
import {songRecentlyService} from "@/apis/music"

export const useRecentlyStore = defineStore(
    'RecentlyList',
    () => {
        const list = ref<song_info[]>([])
        const listId = ref<number>(0)
        const playListImg = ref<string>(Logo)
        const playListName = ref("最近播放")

        const getPlayListInfo = async ()=> {
            const res = await songRecentlyService()
            list.value = res.data as song_info[]
            if(res.data.length > 0)
            {
                res.data.forEach((item:song_info) => {
                    if(item.album_cover !== '' && item.album_cover !== null)
                    {
                        playListImg.value = item.album_cover
                    }
                })
            }
        }

        const refreshPlayList = async () =>{
            await getPlayListInfo()
        }

        return {
            getPlayListInfo,
            list,
            listId,
            playListImg,
            playListName,
            refreshPlayList
        }
    },
    {
        persist: false
    }
)
